package com.example.memorypoint.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.memorypoint.R;
import com.kongzue.dialogx.dialogs.PopTip;

import java.util.ArrayList;
import java.util.List;

public class DetailAdapter extends RecyclerView.Adapter<DetailAdapter.ViewHolder> {

    AdapterView.OnItemClickListener onItemClickListener;

    public DetailAdapter(ArrayList<Data> weatherResource, int screenWidth) {
        this.mDataList = weatherResource;
        screen = screenWidth;
    }

    private int screen;

    public AdapterView.OnItemClickListener getOnItemClickListener() {
        return onItemClickListener;
    }

    public DetailAdapter setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
        return this;
    }

    public DetailAdapter(List<Data> mDataList) {
        this.mDataList = mDataList;
    }

    private final List<Data> mDataList;

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_custom_recycleview, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        Data data = mDataList.get(position);
        holder.getResource().setBackground(data.getResource());
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public static class Data {
        private Drawable resource;

        public Data(Drawable resource) {
            this.resource = resource;
        }

        public Drawable getResource() {
            return resource;
        }

        public void setResource(Drawable resource) {
            this.resource = resource;
        }
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        View itemView;
        TextView resource;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.itemView = itemView;
            this.resource = itemView.findViewById(R.id.iv_detailView);
        }

        public TextView getResource() {
            return resource;
        }

        public View getItemView() {
            return itemView;
        }

    }
}
